@model Admin.NET.Application.Service.System.LowCode.Dto.Front_CodeGenerate
<template>
  <a-modal
    title="编辑@(@Model.BusName)"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @@ok="handleSubmit"
    @@cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
@if(@Model.LowCodeId == null){
      <a-form :form="form">
@foreach (var column in Model.TableField){
if(@column.ColumnKey == "True"){
        @:<a-form-item v-show="false"><a-input v-decorator="['@column.ColumnName']" /></a-form-item>
} else {
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
        @:<a-form-item label="@column.ColumnComment" :labelCol="labelCol" :wrapperCol="wrapperCol">
} else {
        @:<a-form-item label="@column.ColumnComment" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
}
if (@column.EffectType == "user"){
if (@column.WhetherRequired == "Y"){
          @:<user-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)！'}]}]" />
} else {
          @:<user-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "depart"){
if (@column.WhetherRequired == "Y"){
          @:<depart-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)！'}]}]" />
} else {
          @:<depart-select placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "input"){
if (@column.WhetherRequired == "Y"){
          @:<a-input placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)！'}]}]" />
} else {
          @:<a-input placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "textarea"){
if (@column.WhetherRequired == "Y"){
          @:<a-textarea placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)！'}]}]" :auto-size="{ minRows: 3, maxRows: 6 }"/>
} else {
          @:<a-textarea placeholder="请输入@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
}
}
if (@column.EffectType == "inputnumber"){
if (@column.WhetherRequired == "Y"){
          @:<a-input-number placeholder="请输入@(@column.ColumnComment)" style="width: 100%" v-decorator="['@column.ColumnName', {rules: [{required: true, message: '请输入@(@column.ColumnComment)！'}]}]" />
} else {
          @:<a-input-number placeholder="请输入@(@column.ColumnComment)" style="width: 100%" v-decorator="['@column.ColumnName']" />
}
}
if (@column.EffectType == "select"){
if (@column.WhetherRequired == "Y"){
          @:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]">
            @:<a-select-option v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          @:</a-select>
} else {
          @:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]">
            @:<a-select-option v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          @:</a-select>
}
}
if (@column.EffectType == "radio"){
if (@column.WhetherRequired == "Y"){
          @:<a-radio-group placeholder="请选择@(@column.ColumnComment)}" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]" >
            @:<a-radio v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
          @:</a-radio-group>
} else {
          @:<a-radio-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" >
            @:<a-radio v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-radio>
          @:</a-radio-group>
}
}
if (@column.EffectType == "checkbox"){
if (@column.WhetherRequired == "Y"){
          @:<a-checkbox-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]" >
            @:<a-checkbox v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
          @:</a-checkbox-group>
} else {
          @:<a-checkbox-group placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" >
            @:<a-checkbox v-for="(item,index) in @(@column.ColumnName)Data" :key="index" :value="item.code">{{ item.name }}</a-checkbox>
          @:</a-checkbox-group>
}
}
if (@column.EffectType == "switch"){
if (@column.WhetherRequired == "Y"){
          @:<a-switch v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }], valuePropName: 'checked'}]" />
} else {
          @:<a-switch v-decorator="['@column.ColumnName', { valuePropName: 'checked' }]" />
}
}
if (@column.EffectType == "datepicker"){
if (@column.WhetherRequired == "Y"){
          @:<a-date-picker style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName',{rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]" @@change="onChange@(@column.ColumnName)"/>
} else {
          @:<a-date-picker style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']" @@change="onChange@(@column.ColumnName)"/>
}
}
if (@column.EffectType == "fk"){
if (@column.WhetherRequired == "Y"){
          @:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName', {rules: [{ required: true, message: '请选择@(@column.ColumnComment)！' }]}]">
            @:<a-select-option v-for="(item,index) in  @(@column.FkEntityName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          @:</a-select>
} else {
          @:<a-select style="width: 100%" placeholder="请选择@(@column.ColumnComment)" v-decorator="['@column.ColumnName']">
            @:<a-select-option v-for="(item,index) in @(@column.FkEntityName)Data" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          @:</a-select>
}
}
        @:</a-form-item>
}
}
}
      </a-form>
}else{
      <k-form-build ref="kfb" :value="formDesign" :dynamicData="dynamicData" />
}
    </a-spin>
  </a-modal>
</template>

<script>
@{
    var editData = 0;
    var DateQuery = "N";
}
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "datepicker"){
  DateQuery="Y";
}
if(@column.ColumnKey != "True"){
if(@column.EffectType != "datepicker"){
  editData++;
}
}
}
}
@if(DateQuery == "Y"){
  @:import moment from 'moment'
}
  import {
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
    @:@(@Model.ClassName)Fk@(@column.FkEntityName)List,
}
}
    @(@Model.ClassName)Edit
  } from '@@/api/modular/main/@(@Model.ClassName)Manage'
@if(@Model.LowCodeId != null){
  @:import 'k-form-design/styles/k-form-design.less'
  @:import { sysDictDataListbycode } from '@@/api/modular/system/dictDataManage'
}
  export default {
    data () {
      return {
	    Id: 0,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        record: {},
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.DictTypeCode != ""){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
        @:@(@column.ColumnName)Data: [],
}
}
if (@column.EffectType == "datepicker"){
        @:@(@column.ColumnName)DateString: '',
}
}
}
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
        @:@(@column.FkEntityName)Data: [],
}
}
        visible: false,
        confirmLoading: false,
        dynamicData: @Model.DynamicData,
        formDesign: @Model.FormDesign
      }
    },
    methods: {
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
      @:@(@Model.ClassName)Fk@(@column.FkEntityName)List() {
          @:@(@Model.ClassName)Fk@(@column.FkEntityName)List().then(res => {
            @:this.@(@column.FkEntityName)Data = res.data
          @:})
      @:},
}
}
@if(DateQuery == "Y"){
      @:moment,
}
      // 初始化方法
      edit (record) {
        this.visible = true;
		this.Id = record.id;
        this.$nextTick(() => {
@foreach (var dynamic in Model.DynamicLoad_Dict){
          @:sysDictDataListbycode({code:"@(dynamic.Dynamic)"}).then((data) => { this.dynamicData.@(dynamic.DynamicKey) = data.data });
}
        });
        //深度拷贝 移除VUE的监听，防止INDEX页面值变动
        this.record = JSON.parse(JSON.stringify(record))
@foreach (var column in Model.TableField){
if (@column.DictTypeCode != ""){
if (@column.EffectType == "select" || @column.EffectType == "radio" || @column.EffectType == "checkbox"){
        @:const @(@column.ColumnName)Option = this.$options
        @:this.@(@column.ColumnName)Data = @(@column.ColumnName)Option.filters['dictData']('@column.DictTypeCode')
}
}
}
        this.$nextTick(() => {
          let data = { ...
            {
@foreach (var column in Model.TableField){
              @:@column.OriginalColumnName: record.@column.ColumnName,
}
            }
          }
          this.$refs.kfb.setData(data)
        })
@foreach (var column in Model.TableField){
if(@column.EffectType == "fk" && @column.FkEntityName != "" && @column.FkColumnName != ""){
      @:this.@(@Model.ClassName)Fk@(@column.FkEntityName)List()
}
}
      },
      handleSubmit () {
        this.$refs.kfb.getData().then(values => {
		  values.Id = this.Id
          let data = { ...values };
            @(@Model.ClassName)Edit(data).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
        });
      },
@foreach (var column in Model.TableField){
if (@column.WhetherAddUpdate == "Y"){
if (@column.EffectType == "datepicker"){
      @:onChange@(@column.ColumnName)(date, dateString) {
        @:this.@(@column.ColumnName)DateString = dateString
      @:},
}
}
}
      handleCancel () {
        this.$refs.kfb.reset()
        this.visible = false
      }
    }
  }
</script>
